//
//  LeadPageVC.m
//  NeteaseNewsLY
//
//  Created by dllo on 16/2/24.
//  Copyright © 2016年 www.lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "LeadPageVC.h"
#import "AppDelegate.h"
#import "HomeViewController.h"

@interface LeadPageVC ()<UIScrollViewDelegate>
@property (nonatomic, assign)BOOL isOut;
@end

@implementation LeadPageVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    // 引导页图片数组
    NSArray *arr = [NSArray arrayWithObjects:@"1.jpg", @"2.jpg", nil];
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    // 内容大小
    scrollView.contentSize = CGSizeMake(375 * WIDTH * arr.count, HEIGHT * 667);
    scrollView.pagingEnabled = YES;
    scrollView.delegate = self;
    // 隐藏滚动条
    scrollView.showsHorizontalScrollIndicator = NO;
    [self.view addSubview:scrollView];
    for (NSInteger i = 0; i < arr.count; i++) {
        UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(i * WIDTH * 375, 0, WIDTH * 375, HEIGHT * 667)];
        imgView.image = [UIImage imageNamed:arr[i]];
        [scrollView addSubview:imgView];
        [imgView release];
    }
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    // 偏移量
    if (scrollView.contentOffset.x > WIDTH * 375 + WIDTH * 20) {
        _isOut = YES;
    }
}
// 结束减  速跳转主页
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    AppDelegate *app = [[UIApplication sharedApplication] delegate];
    if (_isOut) {
        [UIView animateWithDuration:1.5 animations:^{
            scrollView.alpha = 0;
        } completion:^(BOOL finished) {
            [scrollView removeFromSuperview];
            // 修改window的根视图
            app.window.rootViewController = app.tabBar;
            [self presentViewController:[[HomeViewController alloc] init] animated:YES completion:^{
                
            }];
        }];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
